package com.arica.mq.test.producer.oneway;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

import java.util.UUID;

public class OnewayProducer {
    public static void main(String[] args) throws Exception{
        //Instantiate with a producer group name.
        DefaultMQProducer producer = new
                DefaultMQProducer("GID_ONE-WAY_MESSAGE");
        // Specify name server addresses.
        producer.setNamesrvAddr("192.168.6.106:9876");
        //Launch the instance.
        producer.start();
        for (int i = 0; i < 20; i++) {
            //Create a message instance, specifying topic, tag and message body.
            Message msg = new Message("topic_one_way" /* Topic */,
                    "tag_one_way" /* Tag */,
                    ("Hello RocketMQ " +
                            i + "_" + UUID.randomUUID()).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
            );
            //Call send message to deliver message to one of brokers.
            producer.sendOneway(msg);

        }
        //Shut down once the producer instance is not longer in use.
//        producer.shutdown();
    }
}
